//
//  OAHistroyViewController.m
//  maocuhuiOASystem
//
//  Created by michael on 16/3/22.
//  Copyright © 2016年 czd. All rights reserved.
//

#import "OAHistroyViewController.h"
#import "OAHistoryCell.h"
#import "OAHistoryModel.h"
#import "GDataDefines.h"
#define Method @"roamHistory"

@interface OAHistroyViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)OAHistoryModel * historyModel;
@property(nonatomic,strong)NSMutableArray * dataArray;

@end

@implementation OAHistroyViewController

-(NSMutableArray*)dataArray{
    if (_dataArray == nil) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"流转历史";
  //  self.tableView.hidden = YES;
    [self loadData];
   //  [_tableview   setSeparatorColor:[UIColor    redColor]];  //设置分割线为蓝色
    // _tableview.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    //_tableview.separatorInset = UIEdgeInsetsMake(20, 0, 0, 0);

}
#pragma mark 加载网络数据
-(void)loadData{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSArray * array = @[@{@"unId":self.fileId},@{@"userId":userId}];
    [HttpTools postWithURL:KexchgeneralURL arrays:array method:Method  success:^(id JSON) {
    
    
   // NSLog(@"%@",JSON);
        self.tableView.hidden = NO;
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
         [self getDetailModel:JSON];
        [self.tableView reloadData];
    } failure:^(NSError *error) {
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
    }];
    }
-(void)getDetailModel:(NSString*)dataString{
     NSData * data = [dataString dataUsingEncoding:NSUTF8StringEncoding];
    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData: data options:0 error:nil];
    //获取根节点（Users）
    GDataXMLElement *rootElement = [doc rootElement];
     //获取根节点下的节点（User）
    
    NSArray *arrData= [rootElement elementsForName:@"数据"];
    for (GDataXMLElement *ser in arrData) {
        NSArray *serr = [ser elementsForName:@"数据要素"];
        for (GDataXMLElement *data in serr) {
            OAHistoryModel * model = [[OAHistoryModel alloc]init];
            GDataXMLElement *filetID = [[data elementsForName:@"序号"] objectAtIndex:0];
            model.number = [filetID stringValue];
            
            GDataXMLElement *setp = [[data elementsForName:@"处理步骤"] objectAtIndex:0];
            model.setp = [setp stringValue];
            
            GDataXMLElement  * worker = [[data elementsForName:@"处理人"] objectAtIndex:0];
            model.worker = [worker stringValue];
            
            GDataXMLElement * receive = [[data elementsForName:@"接收时间"] objectAtIndex:0];
            model.receiveDate = [receive stringValue];
            
            
            GDataXMLElement *send = [[data elementsForName:@"业务流向"] objectAtIndex:0];
            model.sendto = [send stringValue];
            
             GDataXMLElement *complete = [[data elementsForName:@"完成时间"] objectAtIndex:0];
            model.completeTime = [complete stringValue];
            
            GDataXMLElement *status = [[data elementsForName:@"状态"] objectAtIndex:0];
            model.status = [status stringValue];
       
            [self.dataArray addObject:model];
            
        }
       
    }

}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    OAHistoryCell * cell = [OAHistoryCell  cellWihtTableView:tableView];
    OAHistoryModel * model = self.dataArray[indexPath.row];
    cell.historyModel = model;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 246;
}


/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
